from database_oprations import DatabaseOperations
from pyecharts.charts import Line
from pyecharts.options import TitleOpts

# 1、读取数据库中的数据，构建折线图的X轴数据和Y轴数据
database_operation = DatabaseOperations()
conn = database_operation.conn()
cursor = conn.cursor()
cursor.execute('select date, count from python_mysql')
results: tuple = cursor.fetchall()
conn.close()
x_list = []
y_list = []
for r in results:
    x_list.append(r[0])
    y_list.append(r[1])

# 2、构建折线图
line = Line()
line.add_xaxis(x_list)
line.add_yaxis(series_name='折线图练习', y_axis=y_list)

line.render()

